package test.reflact;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public  class MyReflact {
//    public static void main()
    public static <T> void getMyReflact(T t) throws InvocationTargetException,Exception{

        Constructor<?>[] constructors = t.getClass().getConstructors();
        Constructor<?> constructor1 = t.getClass().getConstructor();
        System.out.println(constructor1);
        for (Constructor<?> constructor : constructors) {
            String name = constructor.getName();
            System.out.println(name);
        }
        Field[] declaredFields = t.getClass().getDeclaredFields();
        for (int i = 0; i < declaredFields.length; i++) {
            Object o = declaredFields[i].get(t);
            System.out.println(o);
        }

        Field name = t.getClass().getField("Name");
        name.setAccessible(true);
        Object o = name.get(t);
        System.out.println(o);

        Method[] methods = t.getClass().getMethods();
        for (int i = 0; i < methods.length; i++) {
            methods[i].setAccessible(true);//加快速度
            Object invoke = methods[i].invoke(t);
            System.out.println("invoke  "+invoke);
        }
//        return t;
    }

    public static void main(String[] args) throws Exception{
        MyJavaBean myJavaBean = new MyJavaBean("name","female");
        getMyReflact(myJavaBean);
    }
}
